import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView
    },
    /* {
      path: '/about',
      name: 'about',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/AboutView.vue')
    } */
    // {
    //   path: '/test',
    //   component: () => import('../views/Test.vue')
    // },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/UserLofin/LoginView.vue')
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('../views/UserRegister/RegisterView.vue')
    },
    {
      path: '/404',
      name: 'NoPage404',
      component: () => import('../views/NotFound.vue')
    },
    {
      path: '/:pathMatch(.*)',
      redirect: '/404'
    }
  ]
})

// router.beforeEach((to, from, next) => {
//   const token = localStorage.getItem('token')
//   if (to.path !== '/login') {
//     if (token) {
//       next()
//     } else {
//       ElMessage({
//         message: '请先登录！',
//         duration: 1500,
//         type: 'warning'
//       })
//       next('/login')
//     }
//   } else {
//     next()
//   }
// })

export default router
